package com.lanou.myim.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.easemob.chat.EMGroup;
import com.easemob.chat.EMGroupManager;
import com.easemob.exceptions.EaseMobException;
import com.lanou.myim.R;
import com.lanou.myim.tools.PinyinCode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/3/11.
 */
public class GroupListviewAdapter extends BaseAdapter{
    private List<EMGroup> datas;
    private Context context;
    public GroupListviewAdapter(Context context,List<EMGroup> emGroups){
        this.context = context;
        datas = emGroups;
    }
    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder holder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_listview_group_chat,null);
            holder = new MyViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (MyViewHolder) convertView.getTag();
        }
        holder.textView.setText(datas.get(position).getGroupName());
        return convertView;
    }


    class MyViewHolder{
        ImageView imageView;
        TextView textView;
        public MyViewHolder(View item){
            imageView = (ImageView) item.findViewById(R.id.iv_group);
            textView = (TextView) item.findViewById(R.id.tv_group_name);
        }
    }

    }
